" Author        : $USER
" Created       : 16/12/2023
" License       : MIT
" Description   : unite.vim


function! plugin#unite#keymap() abort
    let g:unite_keymap = get(g:, 'unite_keymap', { 'name': '+unite', 
                \   'B': [':Unite bookmark'	    , 'bookmark' 	],                  
                \   'b': [':Unite buffer buffer_tab'	    , 'buffer' 	    ],                    
                \   'C': [':Unite change'	    , 'change' 	    ],                    
                \   'c': [':Unite command'	    , 'command' 	],                   
                \   'd': [':Unite directory'	, 'directory' 	],                 
                \   'D': {  'name'  : '+directory',
                \           'n'     : [':Unite directory/new'	    , 'directory/new' 	        ],             
                \           'r'     : [':Unite directory_rec'	    , 'directory_rec' 	        ],             
                \           'a'     : [':Unite directory_rec/async'	, 'directory_rec/async' 	],       
                \       }, 
                \   'f': {  'name'  : '+file',
                \           'a'     : [':Unite file/async'	        , 'async' 	 	         	],                      
                \           'n'     : [':Unite file/new'	        , 'file/new' 	         	],                  
                \           'l'     : [':Unite file_list'	        , 'file_list' 	         	],                 
                \           'p'     : [':Unite file_point'	        , 'file_point' 	         	],                
                \           'r'     : [':Unite file_rec'	        , 'file_rec' 	         	],                  
                \           'A'     : [':Unite file_rec/async'	    , 'file_rec/async' 	        ],            
                \           'G'     : [':Unite file_rec/git'	    , 'file_rec/git' 	        ],              
                \           'N'     : [':Unite file_rec/neovim'	    , 'file_rec/neovim' 	    ],           
                \       }, 
                \   'F': [':Unite function'	, 'function' 	],                  
                \   'g': [':Unite grep'	    , 'grep' 	    ],                     
                \   'G': [':Unite grep/git'	, 'grep/git' 	],                  
                \   'h': {  'name' : '+history',
                \           'c': [':Unite history/command'	 	    , 'history/command' 	],           
                \           's': [':Unite history/search'	 	    , 'history/search' 		],            
                \           'u': [':Unite history/unite'	 	    , 'history/unite' 		],             
                \       }, 
                \   'j': [':Unite jump'	                            , 'jump' 	    ],                      
                \   'J': [':Unite jump_point'	                    , 'jump_point' 	],                
                \   'l': [':Unite launcher'	                        , 'launcher' 	],                  
                \   'L': [':Unite line'	                            , 'line' 	 	],                     
                \   'm': [':Unite mapping'	                        , 'mapping' 	],                   
                \   'M': [':Unite menu'	                            , 'menu' 	 	],                      
                \   'n': {  'name'  : '+neosnippet',
                \           's'     : [':Unite neosnippet'	        , 'neosnippet' 	        ],               
                \           'r'     : [':Unite neosnippet/runtime'	, 'neosnippet/runtime' 	],        
                \           'u'     : [':Unite neosnippet/user'	    , 'neosnippet/user' 	],           
                \       }, 
                \   '!': [':Unite output'	        , 'output' 	 	 	 	 		],                    
                \   '~': [':Unite output/shellcmd'	, 'output/shellcmd' 	 		],           
                \   'p': [':Unite process'	        , 'process' 	 	 	 		],                   
                \   'r': [':Unite register'	        , 'register' 	 	 	 		],                  
                \   'R': [':Unite resume'	        , 'resume' 	 	 	 			],                    
                \   '$': [':Unite runtimepath'	    , 'runtimepath' 	 	 		],               
                \   's': [':Unite script'	        , 'script' 	 	 	 			],                   
                \   'S': [':Unite source'	        , 'source' 	 	 	 			],                    
                \   't': [':Unite tab'	            , 'tab' 	 	 	 			],                       
                \   'u': [':Unite ultisnips'	    , 'ultisnips' 	 	 	 		],                
                \   'v': [':Unite vim_bookmarks'	, 'vim_bookmarks' 	 	 		],             
                \   '/': [':Unite vimgrep'	        , 'vimgrep' 	 	 	 		],                  
                \   'w': [':Unite window'	        , 'window' 	 	 	 			],                    
                \ })
    return g:unite_keymap
endfunction

function! plugin#unite#load() abort
    if !exists('g:loaded_unite') && plugin#vimproc#load()
        packadd unite.vim
    endif
    return exists('g:loaded_unite')
endfunction

function! plugin#unite#init() abort
    if plugin#unite#load()
        let g:unite_keymap = plugin#unite#keymap()
        let g:leader_keymap.u = g:unite_keymap
        nnoremap <m-f> :Unite -start-insert file directory<cr>
        nnoremap <m-k> :Unite mapping<cr>
        nnoremap <m-u> :Unite -start-insert sources<cr>
        " " Global options definition. "{{{
        call unite#util#set_default(
                    \ 'g:unite_kind_file_delete_file_command',
                    \ unite#util#is_windows() && !executable('rm') ? 'del /s /y $srcs' :
                    \ executable('rmtrash') ? 'rmtrash $srcs' :
                    \ executable('trash-put') ? 'trash-put $srcs' :
                    \ 'rm $srcs')
        " call unite#util#set_default(
        "             \ 'g:unite_kind_file_delete_directory_command',
        "             \ unite#util#is_windows() && !executable('rm') ? '' :
        "             \ executable('rmtrash') ? 'rmtrash $srcs' :
        "             \ executable('trash-put') ? 'trash-put $srcs' :
        "             \ 'rm -r $srcs')
        " call unite#util#set_default(
        "             \ 'g:unite_kind_file_copy_file_command',
        "             \ unite#util#is_windows() && !executable('cp') ? '' :
        "             \ 'cp -p $srcs $dest')
        " call unite#util#set_default(
        "             \ 'g:unite_kind_file_copy_directory_command',
        "             \ unite#util#is_windows() && !executable('cp') ? '' :
        "             \ 'cp -p -r $srcs $dest')
        " call unite#util#set_default(
        "             \ 'g:unite_kind_file_move_command',
        "             \ unite#util#is_windows() && !executable('mv') ?
        "             \  'move /Y $srcs $dest' : 'mv $srcs $dest')
        " call unite#util#set_default('g:unite_kind_file_use_trashbox',
        "             \ unite#util#is_windows() && unite#util#has_vimproc())
        let g:unite_kind_file_delete_file_command = unite#util#is_windows() ? 'cmd /c del /s /y $srcs' : 'rm $srcs'
        let g:unite_kind_file_delete_directory_command = unite#util#is_windows() ? 'cmd /c rd /s /y $srcs' : 'rm $srcs'
        return v:true
    endif
endfunction

